﻿namespace OverStore.Exceptions
{
    using System;

    /// <summary>
    /// The exception that is thrown when trying to call methods of <see cref="T:OverStore.IPersistenceSession"/> 
    /// with the instance while different instance with equal identifier already registered in session.
    /// </summary>
    public sealed class IdentityReferenceIntegrityException : Exception
    {
        private readonly object _ExistingSessionInstance;
        private readonly object _Duplicate;

        /// <summary>
        /// Initializes new instance of IdentityReferenceIntegrityException.
        /// </summary>
        public IdentityReferenceIntegrityException(object existingInstance, object duplicate)
        {
            if (existingInstance == null)
                throw new ArgumentNullException("existingInstance");
            if (duplicate == null)
                throw new ArgumentNullException("duplicate");
            _ExistingSessionInstance = existingInstance;
            _Duplicate = duplicate;
        }

        /// <summary>
        /// Get object that already registered in session.
        /// </summary>
        public object ExistingSessionObject
        {
            get { return _ExistingSessionInstance; }
        }

        /// <summary>
        /// Get instance which duplicate already registered in session.
        /// </summary>
        public object Duplicate
        {
            get { return _Duplicate; }
        }
    }
}